import pandas as pd
import numpy as np

def deletion_trian_data(X):
    """
    since too many missing data, deletion may not helpful
    :param X:
    :return:
    """
    X = np.asarray(X)
    flag = 0
    for i in range(len(X)):
        if -2 not in X[i]:
            flag += 1
    print flag

def M_imputation(mode='', X=0):
    #TODO: model avrage, using all set
    """
    seprate: mean is better than median, but both less than the normal
    :param mode:
    :param X:
    :return:
    """
    X_content = np.asarray(X)
    X_ = X
    if mode == 'mean':
        for i in range(len(X_content.transpose())):
            x = X_content[:,i]
            mean = np.mean(x)
            x[x<0] = mean
            X_['x'+str(i+1)] = x
    elif mode == 'median':
        for i in range(len(X_content.transpose())):
            x = X_content[:,i]
            median = np.median(x)
            x[x<0] = median
            X_['x'+str(i+1)] = x
    return X_

